// ----------------------------------
// RSDK Project: Sonic Essence
// Script Description: Enemy Health Bar
// Script Author: Tails LP
// ----------------------------------

//-------Aliases-------//

private alias object.value0 : badnik.entityPos
private alias object.value1 : size
private alias object.value8 : health


private alias 0 : INITIATE
private alias 1 : IDLE
private alias 2 : VANISH
private alias 3 : DELETE

//-------Function declarations-------//

//-------Static Values-------//

//-------Tables-------//


//-------Functions-------//


event ObjectMain
		object.inkEffect = INK_ALPHA

		arrayPos0 = badnik.entityPos

		health = object[arrayPos0].value8

		object.xpos = object[arrayPos0].xpos
		temp1 = object[arrayPos0].ypos
		temp1 -= 0x280000
		object.ypos = temp1

	switch object.state
	case INITIATE
		object.alpha = 255
		if health <= 0
			object.state = DELETE
		else
			object.state = IDLE
		endif
		break
	case IDLE
		if health <= 0
			object.state = VANISH
		endif
		break
	case VANISH
		if object.alpha >= 0
			object.alpha -= 8
		else
			object.state = DELETE
		endif
		break
	case DELETE
		object.type = 0
		break
	endswitch
end event

event ObjectDraw
	DrawSpriteFX(0, FX_INK, object.xpos, object.ypos)
	if health > 0
		DrawSprite(health)
	endif
end event

event ObjectStartup
    	LoadSpriteSheet("Global/HUD.gif")
	SpriteFrame(-33, -2, 66, 4, 230, 2)	//00 Health Bar
	SpriteFrame(-32, -1, 16, 2, 231, 7)	//01 Health Value 1/4
	SpriteFrame(-32, -1, 32, 2, 231, 7)	//01 Health Value 2/4
	SpriteFrame(-32, -1, 48, 2, 231, 7)	//01 Health Value 3/4
	SpriteFrame(-32, -1, 64, 2, 231, 7)	//01 Health Value 4/4
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 223, 172)
end event